package com.example;

import com.example.Controller.Test;
import com.example.Controller.TestImpl;
import com.example.config.ApplicationConfig;
import com.example.entity.Student;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.SQLException;

public class Main {
    public static void main(String[] args) throws SQLException {
        TestImpl testImpl = new TestImpl();
        testImpl.func("一键三连");
        // 动态代理
        // 1.获取类加载器
        ClassLoader classLoader = Main.class.getClassLoader();
        // 2. 获取被代理类实现接口的字节码对象数据
        Class<?>[] interfaces = TestImpl.class.getInterfaces();
        Test test = (Test) Proxy.newProxyInstance(classLoader, interfaces, new InvocationHandler() {
            // 使用代理对象的方法时调用invoke方法
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return null;
            }
        });

        test.func("一键三连");
    }
}
